﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
using RenrenApi;

namespace Web
{
    public partial class Home : System.Web.UI.Page
    {
        static private Random r = new Random();
        protected void Page_Load(object sender, EventArgs e)
        {
            int MaxSkip = r.Next(0, 30);
            if (Session["client"] == null) // 未授权
            {
                Response.Redirect("index.aspx");
                return;
            }  
            if (allThingPage.Value.Equals("")) allThingPage.Value = "0";
            if (MyRandom.Value.Equals("")) MyRandom.Value = MaxSkip.ToString();
            VistedCourse_Load(new HomeBll().getCoursesByCUserVisit(((RenrenApiClient)Session["client"]).Uid));
            fillCourse();
            fillNewThing();
          
        }

        protected void fillNewThing()
        {
            Repeater_NewThing.DataSource = new HomeBll().getAllThing(int.Parse(allThingPage.Value));
            Repeater_NewThing.DataBind();
        }
        
        protected void fillCourse()
        {
            Repeater_visit.DataSource = new HomeBll().getCourseByRecommend(int.Parse(MyRandom.Value.ToString()));
            Repeater_visit.DataBind();
            Repeater_Gold.DataSource = new HomeBll().getCourseByGold(int.Parse(MyRandom.Value.ToString()));
            Repeater_Gold.DataBind();
            Repeater_Mark.DataSource = new HomeBll().getCourseByMark(int.Parse(MyRandom.Value.ToString()));
            Repeater_Mark.DataBind();
        }

        protected void VisitDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            int index = e.Item.ItemIndex;
            Course course = (Course)e.Item.DataItem;
            StringBuilder prefix = new StringBuilder();
            StringBuilder suffix = new StringBuilder();
            if (index == 2)
            {
                prefix.Append("<li style=\"margin-right: 0;\"><a href=\"" + "course.aspx?id=" + course.ID +
                          "\" class=\"course\" title=" + course.CourseName + ">" + Utility.ShortenClassName(course.CourseName) + "</a>");
                prefix.Append("<a href=\"" + "teacher.aspx?id=" + course.Teacher.ID + "\" class=\"teacher\" title=" + Utility.FullName(course.Teacher.TeacherName) + ">" +
                              Utility.ShortenTeacherName(course.Teacher.TeacherName) + "</a>");
                prefix.Append("<p class=\"browse\"><span>" + course.CourseInfo.RcmdNum + "</span>推荐</p>");
                suffix.Append(
                    "<div class=\"bar_list\"><span class=\"bar_label\">含金量</span><div class=\"bar\"><div class=\"bar1_head\"></div><div class=\"bar1_body\" style=\"width:");
                suffix.Append(course.CourseInfo.Gold * 12.4);
                suffix.Append("px;\"> </div><div class=\"bar1_foot\"><span>" + Utility.Round(course.CourseInfo.Gold) +
                              "</span></div></div></div>");
                suffix.Append(
                    "<div class=\"bar_list\"><span class=\"bar_label\">轻松度</span><div class=\"bar\"><div class=\"bar2_head\"></div><div class=\"bar2_body\" style=\"width:");
                suffix.Append(course.CourseInfo.Relax * 12.4);
                suffix.Append("px;\"></div><div class=\"bar2_foot\"><span>" + Utility.Round(course.CourseInfo.Relax));
                suffix.Append(
                    "</span></div></div></div><div class=\"bar_list\"><span class=\"bar_label\">成绩值</span><div class=\"bar\"><div class=\"bar3_head\"></div><div class=\"bar3_body\" style=\"width:");
                suffix.Append(course.CourseInfo.Mark * 12.4);
                suffix.Append("px;\"></div><div class=\"bar3_foot\"><span>" + Utility.Round(course.CourseInfo.Mark) +
                              "</span></div></div></div></li>");
            }
            else
            {
                prefix.Append("<li><a href=\"" + "course.aspx?id=" + course.ID +
                          "\" class=\"course\" title=" + course.CourseName + ">" + Utility.ShortenClassName(course.CourseName) + "</a>");
                prefix.Append("<a href=\"" + "teacher.aspx?id=" + course.Teacher.ID + "\" class=\"teacher\" title=" + Utility.FullName(course.Teacher.TeacherName) + ">" +
                              Utility.ShortenTeacherName(course.Teacher.TeacherName) + "</a>");
                prefix.Append("<p class=\"browse\"><span>" + course.CourseInfo.RcmdNum + "</span>推荐</p>");
                suffix.Append(
                    "<div class=\"bar_list\"><span class=\"bar_label\">含金量</span><div class=\"bar\"><div class=\"bar1_head\"></div><div class=\"bar1_body\" style=\"width:");

                suffix.Append(course.CourseInfo.Gold * 12.4);
                suffix.Append("px;\"> </div><div class=\"bar1_foot\"><span>" + Utility.Round(course.CourseInfo.Gold) +
                              "</span></div></div></div>");
                suffix.Append(
                    "<div class=\"bar_list\"><span class=\"bar_label\">轻松度</span><div class=\"bar\"><div class=\"bar2_head\"></div><div class=\"bar2_body\" style=\"width:");
                suffix.Append(course.CourseInfo.Relax * 12.4);
                suffix.Append("px;\"></div><div class=\"bar2_foot\"><span>" + Utility.Round(course.CourseInfo.Relax));
                suffix.Append(
                    "</span></div></div></div><div class=\"bar_list\"><span class=\"bar_label\">成绩值</span><div class=\"bar\"><div class=\"bar3_head\"></div><div class=\"bar3_body\" style=\"width:");
                suffix.Append(course.CourseInfo.Mark * 12.4);
                suffix.Append("px;\"></div><div class=\"bar3_foot\"><span>" + Utility.Round(course.CourseInfo.Mark) +
                              "</span></div></div></div></li>");
            }
            LinkButton button = new LinkButton();
            button.CssClass = "ask_place";
            button.ID =  course.ID.ToString();
            button.Click += CourseClick;
            var label = (Label)e.Item.FindControl("Label_visit");
            label.Controls.Add(new Literal { Text = prefix.ToString() });
            if (course.CoursePlaces.Count() == 0) label.Controls.Add(button);
            label.Controls.Add(new Literal { Text = suffix.ToString() });
        }

        protected void GoldDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            int index = e.Item.ItemIndex;
            Course course = (Course)e.Item.DataItem;
            StringBuilder prefix = new StringBuilder();
            StringBuilder suffix = new StringBuilder();
            if (index == 2)
            {
                prefix.Append("<li style=\"margin-right: 0;\"><a href=\"");
                prefix.Append("course.aspx?id=" + course.ID);
                prefix.Append("\" class=\"course\" title=" + course.CourseName + ">");
                prefix.Append( Utility.ShortenClassName(course.CourseName));
                prefix.Append("</a> <a href=\"teacher.aspx?id=" + course.Teacher.ID + "\" class=\"teacher\" title=" + Utility.FullName(course.Teacher.TeacherName) + ">" + Utility.ShortenTeacherName(course.Teacher.TeacherName));
                suffix.Append(
                    "</a> <div class=\"bar_list\"> <span class=\"bar_label\">含金量</span> <div class=\"bar\"> <div class=\"bar1_head\"> </div> <div class=\"bar1_body\" style=\"width: ");
                suffix.Append(course.CourseInfo.Gold * 12.4);
                suffix.Append("px;\"> </div> <div class=\"bar1_foot\"> <span>");
                suffix.Append(Utility.Round(course.CourseInfo.Gold));
                suffix.Append(
                    "</span></div> </div> </div> <div class=\"bar_list\"> <div class=\"bar_text\"> <span class=\"bar_label\">轻松度</span> <span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Relax));
                suffix.Append(
                    "</span> </div> <div class=\"bar_text\"> <span class=\"bar_label\">成绩值</span> <span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Mark));
                suffix.Append("</span> </div> </div> </li>  ");
            }
            else
            {
                prefix.Append("<li><a href=\"");
                prefix.Append("course.aspx?id=" + course.ID);
                prefix.Append("\" class=\"course\" title=" + course.CourseName + ">");
                prefix.Append( Utility.ShortenClassName(course.CourseName));
                prefix.Append("</a> <a href=\"teacher.aspx?id=" + course.Teacher.ID + "\" class=\"teacher\" title=" + Utility.FullName(course.Teacher.TeacherName) + ">" + Utility.ShortenTeacherName(course.Teacher.TeacherName));
                suffix.Append(
                    "</a> <div class=\"bar_list\"> <span class=\"bar_label\">含金量</span> <div class=\"bar\"> <div class=\"bar1_head\"> </div> <div class=\"bar1_body\" style=\"width: ");
                suffix.Append(course.CourseInfo.Gold * 12.4);
                suffix.Append("px;\"> </div> <div class=\"bar1_foot\"> <span>");
                suffix.Append(Utility.Round(course.CourseInfo.Gold));
                suffix.Append(
                    "</span></div> </div> </div> <div class=\"bar_list\"> <div class=\"bar_text\"> <span class=\"bar_label\">轻松度</span> <span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Relax));
                suffix.Append(
                    "</span> </div> <div class=\"bar_text\"> <span class=\"bar_label\">成绩值</span> <span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Mark));
                suffix.Append("</span> </div> </div> </li>  ");
            }
            LinkButton button = new LinkButton();
            button.CssClass = "ask_place";
            button.ID =  course.ID.ToString();
            button.Click += CourseClick;
            var label = (Label)e.Item.FindControl("Label_gold");
            label.Controls.Add(new Literal { Text = prefix.ToString() });
            if (course.CoursePlaces.Count() == 0) label.Controls.Add(button);
            label.Controls.Add(new Literal { Text = suffix.ToString() });
        }

        protected void MarkDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            int index = e.Item.ItemIndex;
            Course course = (Course)e.Item.DataItem;
            StringBuilder prefix = new StringBuilder();
            StringBuilder suffix = new StringBuilder();
            if (index == 2)
            {
                prefix.Append("<li style=\"margin-right: 0;\"><a href=\"");
                prefix.Append("course.aspx?id=" + course.ID);
                prefix.Append("\" class=\"course\" title=" + course.CourseName + ">");
                prefix.Append( Utility.ShortenClassName(course.CourseName));
                prefix.Append("</a> <a href=\"teacher.aspx?id=" + course.Teacher.ID + "\" class=\"teacher\" title=" + Utility.FullName(course.Teacher.TeacherName) + ">" + Utility.ShortenTeacherName(course.Teacher.TeacherName) + "</a>");
                suffix.Append(
                    "  <div class=\"bar_list\"> 	<div class=\"bar_text\"> 		<span class=\"bar_label\">含金量</span> 	<span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Gold));
                suffix.Append(
                    "</span> 						</div> 	<div class=\"bar_text\"> 		<span class=\"bar_label\">轻松度</span> 	<span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Relax));
                suffix.Append(
                    "</span>  	</div> 					</div> <div class=\"bar_list\"> 	<span class=\"bar_label\">成绩值</span> 	<div class=\"bar\"> 	<div class=\"bar3_head\"></div> <div class=\"bar3_body\" style=\"width:");
                suffix.Append(course.CourseInfo.Mark * 12.4);
                suffix.Append("px;\"></div> <div class=\"bar3_foot\"><span>");
                suffix.Append(Utility.Round(course.CourseInfo.Mark));
                suffix.Append("</span></div> </div> </div> 					</li>");

            }
            else
            {
                prefix.Append("<li><a href=\"");
                prefix.Append("course.aspx?id=" + course.ID);
                prefix.Append("\" class=\"course\" title=" + course.CourseName + ">");
                prefix.Append( Utility.ShortenClassName(course.CourseName));
                prefix.Append("</a> <a href=\"teacher.aspx?id=" + course.Teacher.ID + "\" class=\"teacher\" title=" + Utility.FullName(course.Teacher.TeacherName) + ">" + Utility.ShortenTeacherName(course.Teacher.TeacherName) + "</a>");
                suffix.Append(
    "  <div class=\"bar_list\"> 	<div class=\"bar_text\"> 		<span class=\"bar_label\">含金量</span> 	<span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Gold));
                suffix.Append(
                    "</span> 						</div> 	<div class=\"bar_text\"> 		<span class=\"bar_label\">轻松度</span> 	<span class=\"number\">");
                suffix.Append(Utility.Round(course.CourseInfo.Relax));
                suffix.Append(
                    "</span>  	</div> 					</div> <div class=\"bar_list\"> 	<span class=\"bar_label\">成绩值</span> 	<div class=\"bar\"> 	<div class=\"bar3_head\"></div> <div class=\"bar3_body\" style=\"width:");
                suffix.Append(course.CourseInfo.Mark * 12.4);
                suffix.Append("px;\"></div> <div class=\"bar3_foot\"><span>");
                suffix.Append(Utility.Round(course.CourseInfo.Mark));
                suffix.Append("</span></div> </div> </div> 					</li>");
            }
            LinkButton button = new LinkButton();
            button.CssClass = "ask_place";
            button.ID =  course.ID.ToString();
            button.Click += CourseClick;
            var label = (Label)e.Item.FindControl("Label_mark");
            label.Controls.Add(new Literal { Text = prefix.ToString() });
            if (course.CoursePlaces.Count() == 0) label.Controls.Add(button);
            label.Controls.Add(new Literal { Text = suffix.ToString() });
        }

        protected void NewThingDataBound(object sender,RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            int index = e.Item.ItemIndex;
            AllThing newthing = (AllThing)e.Item.DataItem;
            StringBuilder content = new StringBuilder();

            switch (newthing.Type)
            {
                /*
                 * 1。**求**的上课地点
                 * 2。**添加了**课的上课地点***
                 * 3。**在**课中发表题为**的帖子
                 * 4.**回复了**课中***（题目） *****（内容）
                 * 5.**推荐了**课程
                 * 6.**为**课打了分
                 */
                case 1:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>求<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>的上课地点。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 2:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>添加了<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>的上课地点——"+newthing.Place+ "。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 3:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>在<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>中发表了帖子");
                    content.Append("<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">\"" +newthing.Post+"\"</a></h3><span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 4:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>回复了<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>的帖子");
                    content.Append("<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">\"" +newthing.Post+"\"</a></h3><span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span>");
                    content.Append(" <div class=\"content_container\"> <div class=\"quotation_left\"> </div> <p class=\"added_index\"> ");
                    content.Append(newthing.Reply);
                    content.Append("<p> <div class=\"quotation_right\"> </div> </div> </div> </div> ");
                    break;
                case 5:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>推荐了<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>课程。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 6:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>为<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>打了分。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 7:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>想上<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 8:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>在上<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 9:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>上过<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
                case 10:
                    content.Append("<div class=\"news_list\"> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId+"\" target=\"_blank\"> <img src=\"");
                    content.Append(newthing.UserPic);
                    content.Append("\" width=\"50\" height=\"50\" /></a> <div class=\"news_content\"> <h3> <a href=\"");
                    content.Append("http://www.renren.com/profile.do?id=" + newthing.UserId + "\" target=\"_blank\">");
                    content.Append(newthing.UserName);
                    content.Append("</a>关注<a href=\"");
                    content.Append("course.aspx?id=" + newthing.ClassId);
                    content.Append("\">");
                    content.Append(newthing.ClassName);
                    content.Append("</a>。</h3> <span class=\"time\">");
                    content.Append(Utility.GetTimeSpan(newthing.Time));
                    content.Append("</span> </div> </div>");
                    break;
            }
            content.Append(
                "  <div class=\"line_light\"> <div class=\"light_left\"> </div> <div class=\"light_right\"> </div> </div>");
            var label = (Label)e.Item.FindControl("Label_NewThing");
            label.Controls.Add(new Literal { Text = content.ToString() });

        }
        protected void CourseClick(object sender, EventArgs e)
        {
            var button = sender as LinkButton;
            string courseid = "";
            if(button != null)
                courseid = button.ID.ToString();
            Response.Redirect("course.aspx?id=" + courseid);
        }

        // 点击搜索按钮
        protected void HeaderSearchBox_Click(object sender, EventArgs e)
        {
            Response.Redirect("search.aspx?type=10&value=" + search_input.Text);
        }

        // 加载用户访问的课程
        protected void VistedCourse_Load(List<Course> data)
        {
            visitedcourse_repeator.DataSource = data;
            visitedcourse_repeator.DataBind();
        }

        // 用户访问的课程绑定
        protected void VisitedCourse_Bound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            if (e.Item.ItemIndex % 3 == 2)
            {
                ((Literal)e.Item.FindControl("visitedcourse_item")).Text = "<li style=\"margin-right: 0;\">";
                return;
            }
            ((Literal)e.Item.FindControl("visitedcourse_item")).Text = "<li>";
        }

        protected void expand_middle_Click(object sender, EventArgs e)
        {
            allThingPage.Value=(int.Parse(allThingPage.Value) + 1).ToString();
            fillNewThing();
        }

        protected void up_expand_middle_Click(object sender, EventArgs e)
        {
            allThingPage.Value = (int.Parse(allThingPage.Value) - 1).ToString();
            fillNewThing();
        }
    }
}